var ll = new Vue({
    el: "#login",
    data: {
        usernum: "",
        userpass: "",
        code: "",
        codeurl: "../member/sendsms.do",
        loginurl: "../member/doaction.do",
        codebutton: "获取短信验证码",
        wait: 60,
        codedisabled: !1, 
        postdisabled: !1,
        str: /\登录成功!/g ,
        errstr:/\验证码已过期/g
    },
    methods: {
        sendAuthenticationCode() {
            if(this.usernum){
                this.$http.post(this.codeurl, {
                    enews:"login",
                    MerchantId:this.usernum
                }, {
                    emulateJSON: true
                }).then(
                    result => {
                        if(result.body.msg_code==="0000"){
                            this.time();
                            alert(result.body.msg)
                        }else{
                            alert("错误代码："+result.body.msg_code+","+result.body.msg)
                        }
                    }
                );
            }else{
                alert("请输入商户号")
            } 
        },
        time() {
            if (this.wait == 0) {
                this.codebutton = "获取短信验证码";
                this.codedisabled = !1;
                this.wait = 60;
            } else {
                this.codedisabled = !0;
                this.codebutton = "重新发送(" + this.wait + ")";
                this.wait--;
                setTimeout("ll.time()", 1000)
            }
        },
        login() {
            if(this.usernum&&this.userpass){
                this.$http.post(this.loginurl, { 
                    enews: "login", 
                    tobind: '0',
                    username: this.usernum,
                    password: this.userpass,
                    lifetime: 0,
                    dkey:this.code
                }, {
                    emulateJSON: true
                }).then(
                    result => {
                        if(this.str.test(result.body)){
                            sessionStorage.setItem("userid", this.usernum);
                            window.location.href = "index.html";
                        }else{
                            var s=/\您的用户名或密码有误!/g;
                            if(s.test(result.body)){
                                alert("用户名或密码错误")
                            }else{
                                alert("错误代码："+result.body.msg_code+","+result.body.msg)
                            }
                        }
                    }
                );
            }else{
                alert("用户名或密码不能为空")
            }  
        }
    }

})